<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="huoyun" uri="/huoyun"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
	<script type="text/javascript">
	$(document).ready(function(){
		var valid = $("#modifyAddressForm").validate({
				errorPlacement: function(error, element) {
					    // element.parent("td").append(error);
					     element.attr("title", error.html());
					   },
					rules : {
					"address.username":
	  				{
	  					required: true
	  				},
	  				"address.province":{
	  					required: true
	  				},
	  				"address.city":{
	  					required: true
	  				},
	  				"address.town":{
	  					required: true
	  				},
	  				"address.address":{
	  					required: true
	  				},
	  				"address.postalCode":
	  				{
	  					required: true,
	  					zipCode: true
	  				},
	  				"address.mobilePhone":
	  				{
	  					required: true,
	  					mobile: true
	  				},
	  				"address.telephone":
	  				{
	  					phone: true
	  				}
				},
				messages : {
					"address.username":
	  				{
	  					required: "必填项"
	  				},
	  				"address.province":{
	  					required: "必填项"
	  				},
	  				"address.city":{
	  					required: "必填项"
	  				},
	  				"address.town":{
	  					required: "必填项"
	  				},
	  				"address.address":{
	  					required: "必填项"
	  				},
	  				
	  				"address.postalCode":
	  				{
	  					required: "必填项",
	  					zipCode: "邮政编码格式错误"
	  				},
	  				"address.mobilePhone":
	  				{
	  					required: "必填项",
	  					mobile: "请输入正确的手机号码" 
	  				},
	  				"address.telephone":
	  				{
	  					phone: "电话号码格式错误"
	  				}
				}
			});	
			$('#modifyAddressForm').submit(function()//提交表单
	        {
	           
	           	var options = { 
		            //target:'#Tip',
		            url:'${pageContext.request.contextPath}/ajaxAddress/ajaxModifyAddress.action',
		            type:'POST',
		            dataType:'json',
		            beforeSubmit:  function() {
		            },
		            success: function(data){
		            	var res=eval('('+data+')');
		            	var str="<td><input type='radio' name='invoice.addressId' value='"+res.id+"' /></td>"
		            				+"<td>"+res.username+"</td>"
		            				+"<td>"+res.province + res.city + res.town+"</td>"
		            				+"<td>"+res.address+"</td>"
		            				+"<td>"+res.postalCode+"</td>"	
		            				+"<td>"+res.telephone+"/"+res.mobilePhone+"</td>"
		   +"<td><a href='javascript:void(0);' onclick='modifyAddress(\""+res.id+"\")'>修改</a>&nbsp;|&nbsp;<a href='javascript:void(0);' onclick='deleteAddress(\""+res.id+"\")'>删除<a></td></tr>";
		 
					   $('#line_'+res.id).html(str);
		            	simpleBox.close();
		            }
	            }; 
	           	if (valid.form() == true){
	            	$('#modifyAddressForm').ajaxSubmit(options); 
	            }
	            return false;
	        });
		});
		
	</script>
	
		<div id="car_driver_info_div" class="form_wrap clearfix"
			style="min-width: 400px; max-height: 500px;">
			<div style="color: red; margin-left: 100px;">
				<s:property value="resultMsg" />
				<s:fielderror></s:fielderror>
			</div>
			<form id="modifyAddressForm">
				<table class="tableForm">
					<tbody>
						<tr>
							<td class="tdLabel">
								<span class="required-field">*</span>收发票人姓名:
							</td>
							<td class="tdValue">
								<input class="text" type="text" name="address.username" value="<s:property value="address.username"/>" />
							</td>
						</tr>
						<tr>
							<td class="tdLabel">
								<span class="required-field">*</span>所在区域:
							</td>
							<td class="tdValue">
								<huoyun:regionSelect provinceName="address.province"  provinceValue="${address.province}" 
								cityName="address.city" cityValue="${address.city}" 
								townName="address.town"  townValue="${address.town}" />
							</td>
						</tr>

						<tr>
							<td class="tdLabel">
								<span class="required-field">*</span>详细地址:
							</td>
							<td class="tdValue">
								<input class="text" type="text" style="width: 313px;"
									name="address.address" id="address.address" value="<s:property value="address.address"/>"/>
							</td>
						</tr>
						<tr>
							<td class="tdLabel">
								<span class="required-field">*</span>邮政编码:
							</td>
							<td class="tdValue">
								<input type="text " name="address.postalCode"
									id="address.postalCode" class="text" value="<s:property value="address.postalCode"/>"/>
							</td>
						</tr>
						<tr>
							<td class="tdLabel">
								<span class="required-field">*</span>手机号码:
							</td>
							<td class="tdValue">
								<input type="text" name="address.mobilePhone"
									id="address.mobilePhone" class="text" value="<s:property value="address.mobilePhone"/>" />
							</td>
						</tr>
						<tr>
							<td class="tdLabel">
								座机号码:
							</td>
							<td class="tdValue">
								<input type="text" name="address.telephone"
									id="address.telephone" class="text" value="<s:property value="address.telephone"/>" />
							</td>
						</tr>
						<tr>
							<td></td>
							<td class="tdValue">
								<input type="submit" class="default_btn" value="保存">
							</td>
						</tr>
					</tbody>
				</table>
			</form>
		</div>